﻿
IF object_id(N'dbo.UDS_File_File', N'U') IS NULL
BEGIN
    CREATE TABLE dbo.UDS_File_File
    (
        FileId          int             NOT NULL IDENTITY(1,1),
        DirectoryId     int             NOT NULL,
        [Name]          nvarchar(256)   COLLATE Chinese_PRC_CI_AS NOT NULL,
        [Version]       int             NOT NULL CONSTRAINT [DF_UDS_File_File_Version] DEFAULT(1),
        [Size]          int             NOT NULL,
        VPath           nvarchar(512)   COLLATE Chinese_PRC_CI_AS NOT NULL,
        TimeCreated     datetime        NOT NULL CONSTRAINT [DF_UDS_File_File_TimeCreated] DEFAULT(getdate()),
        LastModified    datetime        NOT NULL CONSTRAINT [DF_UDS_File_File_LastModified] DEFAULT(getdate()),
        
        CONSTRAINT [PK_UDS_File_File] PRIMARY KEY NONCLUSTERED (FileId asc),
        CONSTRAINT [FK_UDS_File_File_DirectoryId] FOREIGN KEY (DirectoryId) REFERENCES dbo.UDS_File_Directory(DirectoryId)
    );
    
    CREATE CLUSTERED INDEX [CX_UDS_File_File] ON dbo.UDS_File_File
    (
        DirectoryId asc,
        [Name] asc
    );
END
GO